package com.example.maxboxtwo.components.function.LED;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.maxboxtwo.R;

public class LEDFunction extends View {
    private Bitmap bitmap;
    private Paint paint;
    private int[][]small;
    private int[][]big;
    private boolean one=false,two=false,three=false,four=false,five=false;
    public int[][] getSmall() {
        return small;
    }

    public void setSmall(int[][] small) {
        this.small = small;
    }

    public int[][] getBig() {
        return big;
    }

    public void setBig(int[][] big) {
        this.big = big;
    }

    public LEDFunction(Context context) {
        super(context);
    }

    public LEDFunction(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public LEDFunction(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        small=new int[0][0];
        big = new int[0][0];
        if(bitmap==null)
        bitmap = bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.led_touch_dot),30,30,false);
        paint=new Paint();
        paint.setDither(true);
        paint.setFilterBitmap(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(getWidth()/2,getHeight()/2);
        // draw left part and opposite with next for
        if(five){
            for (int count=0;count<big.length;count++){
                canvas.drawBitmap(bitmap,-big[count][0],big[count][1],paint);
            }
        }

        if(four){
            for (int count=0;count<big.length;count++){
                canvas.drawBitmap(bitmap,big[count][0],big[count][1],paint);
            }
            five=true;
        }

        if(three){
            for (int count=4;count<6;count++){
                canvas.drawBitmap(bitmap,-small[count][0],small[count][1],paint);
            }
            four=true;
        }

        if(two){
            for (int count=4;count<6;count++){
                canvas.drawBitmap(bitmap,small[count][0],small[count][1],paint);
            }
            three=true;
        }

        if(one){
            for (int count=0;count<4;count++){
                canvas.drawBitmap(bitmap,-small[count][0],-small[count][1],paint);
            }
            two=true;
        }

        // draw point of heart
        if(small.length>0){
        for (int count=0;count<4;count++){
            canvas.drawBitmap(bitmap,small[count][0],-small[count][1],paint);
        }
        one=true;
        }
    }
}
